package leetcode.easy.limit500;

import java.util.Stack;

public class No415 {
    public static void main(String[] args) {
        String num1 = "11";
        String num2 = "123";
        System.out.println(new No415().addStrings(num1, num2));
    }

    public String addStrings(String num1, String num2) {
        int m = num1.length();
        int n = num2.length();
        int i = m - 1, j = n - 1;
        StringBuilder ans = new StringBuilder();
        int tag = 0;
        while (i >= 0 || j >= 0) {
            int a = i >= 0 ? num1.charAt(i) - '0' : 0;
            int b = j >= 0 ? num2.charAt(j) - '0' : 0;
            tag += a + b;
            ans.append(tag % 10);
            tag /= 10;
            i--;
            j--;
        }
        if (tag != 0)
            ans.append(tag);
        return ans.reverse().toString();
    }
}
